<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/15
 * Time: 22:18
 */

namespace App\Library\form_builder\src\traits;
use App\Library\form_builder\src\components\Input;

trait InputTrait
{
    /**
     * input输入框组件
     *
     * @param        $field
     * @param        $title
     * @param string $value
     * @param string $type
     * @return Input
     */
    public static function input($title,$field, $value = '', $type = Input::TYPE_TEXT)
    {

        $input = new Input($title,$field, (string)$value);
        $input->type($type);
        return $input;
    }

    /**
     * text 类型输入框
     *
     * @param        $field
     * @param        $title
     * @param string $value
     * @return Input
     */
    public static function text($title,$field, $value = '')
    {
        return self::input($title,$field, $value);
    }

    /**
     * password 类型输入框
     *
     * @param        $field
     * @param        $title
     * @param string $value
     * @return Input
     */
    public static function password($title,$field, $value = '')
    {
        return self::input($title,$field, $value, Input::TYPE_PASSWORD);
    }

    /**
     * url 类型输入框
     *
     * @param        $field
     * @param        $title
     * @param string $value
     * @return Input
     */
    public static function url($title,$field, $value = '')
    {
        return self::input($title,$field, $value, Input::TYPE_URL);
    }

    /**
     * email 类型输入框
     *
     * @param        $field
     * @param        $title
     * @param string $value
     * @return Input
     */
    public static function email($title,$field, $value = '')
    {
        return self::input($title,$field, $value, Input::TYPE_EMAIL);
    }
    /**
     * date 类型输入框
     *
     * @param        $field
     * @param        $title
     * @param string $value
     * @return Input
     */
    public static function idate($title,$field, $value = '')
    {
        $input=new Input($title,$field, $value);
        $input->set_props([
            'id'=>'date',
            'autocomplete'=>'off'
        ]);
        return $input;
    }
}